﻿Imports Fruiterie_Atwater.fruiterieAtwaterMP

Public Class login
    Inherits Fruiterie_Atwater.Pagedb


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsNothing(Request.Cookies.Get("fruitAtwaterUserMail")) Then

            Dim cookieCourant As HttpCookie = Request.Cookies.Get("fruitAtwaterUserMail")

            TxtBoxUtilisateur.Text = cookieCourant.Value.ToString
        End If

        'Gestion des actions autorisées
        'basées sur la QueryString
        Select Case Request.QueryString("loginAction")
            Case "renew"
                PanelForgetPwd.Visible = True
            Case "desinscription"
                Response.Write("poutine")
        End Select


    End Sub

    Private Sub SubmitLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitLogin.Click
        'Attention validation requise
        Dim userClient As New client
        Dim nomUtilisateur As String = String.Empty
        Dim flag As Boolean = False

        userClient = man.getClientByCred(TxtBoxUtilisateur.Text.ToString(), TxtBoxMdp.Text.ToString())

        If Not IsNothing(userClient) Then

            'Création du panier session uniquement
            'si l'acces est granted
            Session("panier") = New Hashtable

            HttpContext.Current.Session.Add("client", userClient)
            nomUtilisateur = userClient.prenomClient.ToString & " " & userClient.nomClient.ToString()

            If CheckBoxConfCGU.Checked Then
                Dim cookieUserMail As HttpCookie = New HttpCookie("fruitAtwaterUserMail")
                cookieUserMail.Value = userClient.courrielClient.ToString
                Response.Cookies.Add(cookieUserMail)
                flag = True
            End If

            FormsAuthentication.SetAuthCookie(nomUtilisateur, flag)

            Response.Redirect("/index.aspx")
        Else
            LabelUtilisateurNoticeLogin.Visible = True
            LabelUtilisateurNoticeLogin.Text = "Votre login ou votre mot de passe ne semblent pas correspondre."
        End If
    End Sub



    Private Sub ButtonForgetPwd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonForgetPwd.Click

        'On enleve le panel du DOM
        'PanelForgetPwd.Visible = False
        'Méthode JQuery préférée pour effet suppression DOM


        'Operation BDD à effectuer...



    End Sub
End Class